package com.tarena.util.datasource;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;

public class MetaDataTest {
	public static void main(String[] args){
		Connection conn = null;
		Statement statement =null;
		ResultSet rs = null;
		try {
			conn=DBConnection.getConnection();
			DatabaseMetaData dmd = conn.getMetaData();
			System.out.println(dmd.getDatabaseProductName());
			System.out.println(dmd.getDatabaseProductVersion());
			statement=conn.createStatement();
			rs=statement.executeQuery("select * from dept_snail");
			//获取表信息
			ResultSetMetaData msmd=rs.getMetaData();
			//数据中字段长度
			System.out.println(msmd.getColumnCount());
			for (int i = 1; i <= msmd.getColumnCount(); i++) {
				System.out.println(msmd.getColumnName(i)+"\t"+msmd.getColumnTypeName(i));
			}
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try {
				DBConnection.close(rs,statement, conn);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
